package org.jeecg.modules.solitaire_app.yuyin.controller;

import cn.hutool.json.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.modules.solitaire_app.yuyin.utils.MediaUrlUtil;
import org.springframework.web.bind.annotation.*;


import java.io.IOException;
import java.util.Map;

/**
 * @Description: 语音合成
 * @Author: jeecg-boot
 * @Date: 2023-11-25
 * @Version: V1.0
 */
@Slf4j
@Api(tags = "语音合成")
@RestController
@RequestMapping("/app/media")
public class MediaController {


    @AutoLog(value = "语音合成-获取合成url")
    @ApiOperation(value = "语音合成-获取合成url", notes = "语音合成-获取合成url")
    @PostMapping(value = "/getProvinceList")
    public Result<String> getMediaUrl(@RequestBody Map<String, Object> map) throws IOException {
        Result<String> result = new Result<>();
        String text = map.get("text").toString();
        int voice = Integer.parseInt(map.get("voice").toString());
        String mediaUrl = MediaUrlUtil.getMediaUrl(text, voice);
        if (StringUtils.isNoneEmpty(mediaUrl)){
            result.setCode(200);
            result.setMessage("获取成功");
            result.setResult(mediaUrl);
            result.setSuccess(true);
            return result;
        }else{
            result.setCode(500);
            result.setMessage("合成失败");
            result.setSuccess(false);
            return result;
        }
    }
}
